# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH

# Path to your oh-my-zsh installation.
export ZSH="$HOME/.config/oh-my-zsh"

# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="bracket"
# ZSH_THEME="powerlevel10k/powerlevel10k"
# POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir vcs)
# POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status root_indicator background_jobs time virtualenv)
# POWERLEVEL9K_MODE="nerdfont-complete"

# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in ~/.oh-my-zsh/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )

# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"

# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"

# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"

# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13

# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"

# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"

# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"

# Uncomment the following line to display red dots whilst waiting for completion.
# COMPLETION_WAITING_DOTS="true"

# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"

# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
HIST_STAMPS="yyyy-mm-dd"

# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder

# Which plugins would you like to load?
# Standard plugins can be found in ~/.oh-my-zsh/plugins/*
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(
    git
    z
    extract
    virtualenv
    virtualenvwrapper
    colorize
    cp
    zsh-syntax-highlighting
    zsh-autosuggestions
    fzf
    colored-man-pages
)

source $ZSH/oh-my-zsh.sh

# User configuration

# export MANPATH="/usr/local/man:$MANPATH"

# You may need to manually set your language environment
export LANG=en_US.UTF-8

# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
#   export EDITOR='vim'
# else
#   export EDITOR='mvim'
# fi
export EDITOR='vim'
alias vimdiff='vi -d'

# Compilation flags
# export ARCHFLAGS="-arch x86_64"

# ssh
export SSH_KEY_PATH="~/.ssh/rsa_id"

# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"

export LOCAL=$HOME/.local
export CONF=$HOME/.config
export LOG=$LOCAL/var/log

# npm config
# export NODE_HOME=$HOME/.local/node
# export NODE_PATH=$NODE_PATH:$HOME/.local/npm/lib/node_modules
# export PATH=$HOME/.local/npm/bin:$NODE_HOME/bin:$PATH

function update_dlv () {
    go install github.com/go-delve/delve/cmd/dlv@latest
}

# golang config
goinfo=$(echo $(which go))
if [[ $goinfo =~ "not found" ]]; then
    echo "go not found"
else
    export GOPATH=$HOME/Projects/Go
    export PATH=$HOME/.local/bin:$GOROOT/bin:$GOPATH/bin:$PATH
    # export GOROOT=$(go env | grep -Eo '(GOROOT=.*)' | grep -Eo '(=.*)' | sed 's/=//g' | sed 's/"//g')
    export $(go env | grep 'GOROOT' | sed 's/"//g')
    # export GOROOT=$HOME/.local/go
    # :${JAVA_HOME}/bin:${PATH}
    export GO111MODULE=on
fi
# 阿里云镜像
# export GOPROXY=https://mirrors.aliyun.com/goproxy/
# 中国golang镜像
# GOPROXY=https://goproxy.io
# go env -w GOPROXY=https://goproxy.cn,direct
export GOPROXY=https://goproxy.cn

# rust config
export CARGO_HOME=$HOME/.cargo
export PATH=$CARGO_HOME/bin:$PATH

# [[ -f ~/.fzf.zsh ]] && source ~/.fzf.zsh

# MacOS settings
if [[ $(uname -s) = "Darwin" ]]; then
    # icoding
    export ICODING_HOME=$HOME/.local/icoding
    export PATH=$ICODING_HOME:$PATH

    # MySQL 5.7 at MacOS
    # For compilers to find mysql@5.7
    if [[ $(uname -m) = "arm64" ]]; then
        export MYSQL_HOME="/opt/homebrew/Cellar/mysql@5.7/5.7.38"
        export LDFLAGS="-L/opt/homebrew/opt/mysql@5.7/lib"
        export CPPFLAGS="-I/opt/homebrew/opt/mysql@5.7/include"
        export PATH="/opt/homebrew/opt/go@1.17/bin:$PATH"
    else
        export MYSQL_HOME="/usr/local/opt/mysql@5.7"
        export LDFLAGS="-L/usr/local/opt/mysql@5.7/lib -L/usr/local/opt/openssl@1.1/lib"
        export CPPFLAGS="-I/usr/local/opt/mysql@5.7/include -I/usr/local/opt/openssl@1.1/include"
    fi
    export PATH=$MYSQL_HOME/bin:$PATH
    export PKG_CONFIG_PATH=$MYSQL_HOME/lib/pkgconfig

    # export VIRTUALENVWRAPPER_PYTHON="/usr/local/bin/python3"
    export PATH="/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands":$PATH
    # export GITSTATUS_LOG_LEVEL=DEBUG
    # tig_completion=/usr/local/etc/bash_completion.d/tig-completion.bash
    # if [[ -f $tig_completion ]]; then
    #     source $tig_completion
    # fi
    # android platform-tools
    export PATH="$HOME/.local/platform-tools":$PATH
    # php config
    # export PATH="/opt/homebrew/opt/php@7.4/bin:$PATH"
    # export PATH="/opt/homebrew/opt/php@7.4/sbin:$PATH"
    # export LDFLAGS="-L/opt/homebrew/opt/php@7.4/lib"
    # export CPPFLAGS="-I/opt/homebrew/opt/php@7.4/include"
    alias sed="gsed"
    # export GOPROXY=https://goproxy.baidu-int.com
    # Update homebrew config
    export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
    export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"
    export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"

    # node@16
    export PATH="/opt/homebrew/opt/node@16/bin:$PATH"
    # set go build
    export GO_1_17_BIN=$GOROOT/bin
    export GO_1_18_BIN=$GOROOT/bin
# Linux settings
elif [[ $(uname -s) = "Linux" ]]; then
    alias pbcopy="xclip -sel clipboard"
    alias pbpaste="xclip -sel clipboard -o"
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/cuda/lib64/

    # Java config
    export JAVA_HOME=$HOME/.local/jvm/openjdk11
    export JRE_HOME=${JAVA_HOME}/jre
    export CLASS_PATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
    export PATH=$JAVA_HOME/bin:$PATH
elif [[ $(uname -s) = "freebsd" ]]; then
    # TODO: finish when I have a freebsd system
    alias la="ls -ahl"
fi

VIRTUALENV_PATHS=(
    "/usr/bin/virtualenvwrapper.sh"
    "/usr/local/bin/virtualenvwrapper.sh"
    "/opt/homebrew/bin/virtualenvwrapper.sh")

for VIRTUALENV in ${VIRTUALENV_PATHS[@]}
do
    if [[ -f $VIRTUALENV ]]; then
        source $VIRTUALENV
        break
    fi
done
unset VIRTUALENV_PATHS

# if type kitty >/dev/null 2>&1; then
#     alias icat="kitty +kitten icat"
#     alias kssh="kitty +kitten ssh"
# fi
